<template>
  <div class="container-home">
    <!-- 头部 -->
    <div class="header-wrap" :class="scrollTop? 'on' : '' ">
      <div class="header">
        <div class="header-logo">
          <img src="../assets/project-logo.png" alt="">
        </div>
        <div class="header-input">
          <div class="address">
            <span>长沙</span>
          </div>
          <div class="input-content">
            <van-field class="field" @click="toSearch" v-model="searchWords" placeholder="请输入关键字找店铺" />
          </div>
          <div class="search-btn"></div>
        </div>
        <div class="login" v-if="!userInfo.salesManNickName" @click="toLogin">登录/注册</div>
        <div class="login" v-else @click="toLogin">个人中心</div>
      </div>
    </div>
    <!-- 轮播 -->
    <div class="banner">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item v-for="item in advertiseList" :key="item.componentName">
          <img :src="item.componentValue" alt="">
        </van-swipe-item>
      </van-swipe>
    </div>
    <!-- 通告栏 -->
    <div class="tips">
      <van-notice-bar left-icon="volume-o" :scrollable="false">
          <van-swipe
            vertical
            class="notice-swipe"
            :autoplay="3000"
            :show-indicators="false"
          >
          <van-swipe-item v-for="item in newArr" :key="item.componentTitle">
            {{item.componentTitle}}
          </van-swipe-item>
        </van-swipe>
      </van-notice-bar>
    </div>
    <!-- 导航栏 -->
    <div class="nav">
      <div class="nav-list">
        <div class="nav-item" @click="toprojectList">
          <div class="pic">
            <img src="../assets/nav1.png" alt="">
          </div>
          <div class="text">找项目</div>
        </div>
        <div class="nav-item" @click="toroomList">
          <div class="pic">
            <img src="../assets/nav2.png" alt="">
          </div>
          <div class="text">租店铺</div>
        </div>
        <div class="nav-item" @click="towork">
          <div class="pic">
            <img src="../assets/nav3.png" alt="">
          </div>
          <div class="text">项目合作</div>
        </div>
        <div class="nav-item" @click="tounderstand">
          <div class="pic">
            <img src="../assets/nav4.png" alt="">
          </div>
          <div class="text">了解躺猪网</div>
        </div>
        <div class="nav-item">
          <div class="pic">
            <img src="../assets/nav5.png" alt="">
          </div>
          <div class="text">联系我们</div>
          <a v-bind:href="'tel:'+(phone)"></a>
        </div>
        <!-- <div class="nav-item" @click="gotoroomList">
          <div class="pic">
            <img src="../assets/nav6.png" alt="">
          </div>
          <div class="text">餐饮</div>
        </div>
        <div class="nav-item" @click="gotoroomList">
          <div class="pic">
            <img src="../assets/nav7.png" alt="">
          </div>
          <div class="text">零售</div>
        </div>
        <div class="nav-item" @click="gotoroomList">
          <div class="pic">
            <img src="../assets/nav7.png" alt="">
          </div>
          <div class="text">休闲服务</div>
        </div>
        <div class="nav-item" @click="gotoroomList">
          <div class="pic">
            <img src="../assets/nav7.png" alt="">
          </div>
          <div class="text">生活配套</div>
        </div>
        <div class="nav-item" @click="gotoroomList">
          <div class="pic">
            <img src="../assets/nav7.png" alt="">
          </div>
          <div class="text">儿童娱乐</div>
        </div> -->
      </div>
      <div class="nav-list">
        <div class="nav-item" v-for="item in navList" :key="item.id" @click="gotoroomList(item.name)">
          <div class="pic">
            <img :src="item.img" alt="">
          </div>
          <div class="text">{{item.name}}</div>
        </div>
      </div>
    </div>
    <div class="content">
      <!-- 项目 -->
      <div class="floor f1">
        <div class="hd">
          <div class="floor-title">精选项目</div>
          <div class="title-child">
            <div class="child-left">优质新盘底商推荐，找到你的聚宝盆</div>
            <div class="child-right" @click="toprojectList">更多项目</div>
          </div>
        </div>
        <div class="bd">
          <div class="project-list">
            <div class="project-item" @click="toprojectDetail(item.id,item)" v-for="item in projectList" :key="item.id">
              <div class="pic">
                <img :src="item.realEstateImage" alt="">
                <div class="sale-img" v-if="item.realEstateExclusiveAgent==1">
                  独家项目
                </div>
                <div class="sale-text" v-if="item.viewingBonus>=1&&item.viewingBonus!=null">带看奖励</div>
              </div>
              <div class="project-text">
                <div class="projectList-name">{{item.realEstateName}}</div>
              </div>
              <div class="projectList-address">
                <span>{{item.realEstateDistrict}}-{{item.realEstateModule}}</span>
                <span>待租店铺:{{item.toBeRanted}}</span>
              </div>
              <div class="project-message">{{item.realEstateTitle}}</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 店铺 -->
      <div class="floor f2">
        <div class="hd">
          <div class="floor-title">优质好铺</div>
          <div class="title-child">
            <div class="child-left">成熟街区，人气旺铺</div>
            <div class="child-right" @click="toroomList">更多店铺</div>
          </div>
        </div>
        <div class="bd">
          <div class="room-list">
            <div class="room-item" @click="toroomDetail(item.id)" v-for="item in roomList" :key="item.id">
              <div class="pic">
                <img :src="item.roomPicture" alt="">
                <div class="sale-img" v-if="item.realEstateExclusiveAgent==1">
                  独家项目
                </div>
                <div class="sale-text" v-if="item.viewingBonus>=1&&item.viewingBonus!=null">带看奖励</div>
              </div>
              <div class="room-name">{{item.roomName}}</div>
              <div class="room-address">{{item.realEstateDistrict}}-{{item.realEstateModule}}-{{item.realEstateName}}</div>
              <div class="room-text">
                <div class="room-area">建筑面积{{item.constructionArea}}㎡</div>
                <div class="room-prices">{{item.monthlyRent ? (item.monthlyRent/item.constructionArea + 1).toFixed(0) : 0}} 元/月/㎡</div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- 推荐店铺 -->
      <div class="floor f3">
        <div class="hd">
          <div class="floor-title">推荐列表</div>
          <div class="title-child">
            <div class="child-left">成熟街区，人气旺铺</div>
            <div class="child-right" @click="toroomList">更多店铺</div>
          </div>
        </div>
        <div class="bd">
          <div class="room-list">
            <div class="room-item" @click="toroomDetail(item.id)" v-for="item in recommroomList" :key="item.id">
              <div class="pic">
                <img :src="item.roomPicture" alt="">
                <div class="sale-img" v-if="item.realEstateExclusiveAgent==1">
                  独家项目
                </div>
                <div class="sale-text" v-if="item.viewingBonus>=1&&item.viewingBonus!=null">带看奖励</div>
              </div>
              <div class="room-name">{{item.roomName}}</div>
              <div class="room-address">{{item.realEstateDistrict}}-{{item.realEstateModule}}-{{item.realEstateName}}</div>
              <div class="room-text">
                <div class="room-area">建筑面积{{item.constructionArea}}㎡</div>
                <div class="room-prices">{{item.monthlyRent ? (item.monthlyRent/item.constructionArea + 1).toFixed(0) : 0}} 元/月/㎡</div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- 合作伙伴 -->
      <div class="floor f4">
        <div class="hd">
          <div class="floor-title">合作伙伴</div>
          <div class="title-child">
            <div class="child-left">期待您的加入，请联系客服电话</div>
          </div>
        </div>
        <div class="bd">
          <div class="friend-content">
            <div class="friend-title">已服务品牌</div>
            <div class="friend-list">
              <div class="friend-item" v-for="item in friendsList" :key="item.id">
                <img :src="item.value" alt="">
              </div>
            </div>
            <div class="more" @click="noMore">MORE>></div>
          </div>
        </div>
      </div>
    </div>
    <foot-message></foot-message>
  </div>
</template>

<script>
import wx from 'weixin-js-sdk'
import FootMessage from '@/components/foot-message/index.vue'
import{homeprojectList,homeroomList,recommRoomList,advertisementList,recommTips,recommTipsWord} from"@/api/home"
import{mapActions,mapState} from "vuex"
export default {
  components:{
    FootMessage
  },
  data() {
    return {
      // 客服电话
      phone:'0731-89678615',
      //  精选项目
      projectList:[],
      // 优质好铺
      roomList:[],
      // 推荐店铺
      recommroomList:[],
      // 广告图
      advertiseList:[],
      // 搜索的关键字
      searchWords:"",
      // 滑动监听
      scrollTop:false,
      // 通知消息数组
      newArr:[],
      tipsList:[],
      // friends
      friendsList:[
        {value:'/static/friend1.jpg',id:0},
        {value:'/static/friend2.jpg',id:1},
        {value:'/static/friend3.jpg',id:2},
      ],
      // 导航栏
      navList:[
        {name:"餐饮",img:'/static/nav6.png',id:0},
        {name:"零售",img:'/static/nav7.png',id:1},
        {name:"休闲娱乐",img:'/static/nav8.png',id:2},
        {name:"生活配套",img:'/static/nav9.png',id:3},
        {name:"儿童娱乐",img:'/static/nav10.png',id:4},
      ]
    };
  },
  created(){
    this.loadData()
	  document.title ='躺猪网-好铺好服务找铺上躺猪网！'
  },
  computed:{
    ...mapState(['userInfo','vuexqueryForm'])
  },
  mounted(){
    //  下拉监听
    this.listenerFunction()
  },
  beforeDestroy () {
	//  下拉监听
	document.removeEventListener("scroll", this.listenerFunction);
  },
  methods:{
    ...mapActions(["SaveUserSelect"]),
    // 初始数据
    loadData(){
       // 精选项目
      homeprojectList().then(res=>{
        console.log("项目",res)
        var projectList=[]
        projectList.push(res[0],res[1])
        // console.log(projectList)
        this.projectList=projectList
      })
      // 优质好铺
      homeroomList().then(res=>{
        console.log(res)
        var roomList=[]
        roomList.push(res[0],res[1])
        this.roomList=roomList
      })
      // 推荐店铺
      recommRoomList(4).then(res=>{
        console.log("店铺",res)
        var recommroomList=[]
        recommroomList.push(res[0],res[1])
        this.recommroomList=recommroomList
      })
      // 广告图
      advertisementList(2,{}).then(res=>{
        console.log(res)
        this.advertiseList=res
      })
      // 消息通知
      recommTips().then(res=>{
        console.log("通知消息",res)
        this.tipsList=res
        this.getTips()
      })
      // 分享
      // var ua = window.navigator.userAgent.toLowerCase();
      // if (ua.match(/MicroMessenger/i) == 'micromessenger') {
      //     var dataForWeixin={
      //       title:"【躺猪网】超值好铺抢租中",
      //       imgUrl:'/static/code.jpg',
      //       link:window.location.href
      //     }
      //     this.$share.getJSSDK(dataForWeixin)
      // }
    },
    getTips(){
      // 消息通知/front/end/setting/{componentType}
      recommTipsWord(5,{}).then(res=>{
        console.log("通知消息",res)
        // console.log(this.tipsList[0])
        res[res.length-1].componentTitle=this.tipsList[0]
        console.log(res)
        // var TipsWordList=res
        // var newArr = TipsWordList.concat(this.tipsList);
        // console.log(newArr)
        this.newArr=res
      })
    },
    // 去店铺列表
    toroomList(){
      this.$router.push({path:"/room"})
    },
    // 从导航栏跳转到店铺列表
    gotoroomList(name){
      const{vuexqueryForm}=this
      vuexqueryForm.format=name
      this.SaveUserSelect(vuexqueryForm)
      this.$router.push({path:'/room'})
    },
    // 去项目列表
    toprojectList(){
      this.$router.push({path:"/project"})
    },
    // 去一起工作
    towork(){
      this.$router.push({path:'/work'})
    },
    // 去搜索
    toSearch(){
      this.$router.push({path:'/search'})
    },
    // 去了解躺猪网
    tounderstand(){
      this.$router.push({path:"/understand"})
    },
    // 下拉监听开始
    listenerFunction(e) {
      document.addEventListener('scroll', this.handleScroll, true);
    },
    handleScroll () {
      // console.log(window.pageYOffset)
      if(window.pageYOffset>25){
        this.scrollTop=true
      }else{
        this.scrollTop=false
      }
    },
    // 下拉监听结束

    // 暂无更多
    noMore(){
      this.$router.push({path:"/friends"})
    },
    // 去项目详情
    toprojectDetail(id,item){
      if(item.realEstateTitle=="敬请期待"){
        this.$toast("敬请期待");
      }else{
        this.$router.push({path:"/projectDetail",query:{EngineerId:id}})
      }
    },
    // 去店铺详情
    toroomDetail(id){
      // console.log(id)
      this.$router.push({path:"/roomDetail",query:{roomId:id}})
    },
    // 登录注册
    toLogin(){
      this.$router.push({path:"/user"})
    }
  }
};
</script>
<style lang="less" scoped>
// 头部
.header{
  display: flex;
  background-color: #F3F3F3;
  padding: 0 0.25rem;
  height: 1.1rem;
  align-items: center;
  justify-content: space-around;
}
.header-wrap.on{
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 999;
}
.header-logo{
  display: flex;
  img{
    align-items: center;
    width: 1.92rem;
    height: 0.46rem;
  }
}
.header-input{
  display: flex;
  align-items: center;
  position: relative;
  margin-left: 0.2rem;
  .address{
    font-size: 0.18rem;
    left: 0.1rem;
    position: absolute;
    z-index: 99;
    font-weight: 600;
  }
  .address::before{
    width: 0px;
    height: 0px;
    border-top: 4px solid #494848;
    border-left: 3px solid transparent;
    border-right: 3px solid transparent;
    position: absolute;
    z-index: 99;
    display: block;
    content: "";
    top: 50%;
    transform: translate(0,-50%);
    left: 0.45rem;
  }
  /deep/.van-field__control{
    width: 3.45rem;
    height: 0.6rem;
    font-size: 0.18rem;
    padding: 0 ;
    border-radius: 4px;
    padding-left: 0.96rem;

  }
  /deep/.van-cell{
    padding: 0;
    border-radius: 8px;
  }
  .search-btn{
    font-size: 0.28rem;
    position: absolute;
    right: 0;
  }
}
.login{
  font-size: 0.26rem;
  color: #FF9600;
  font-weight: 600;
  margin-left: 0.2rem;
}

// 轮播图
.banner{
  padding: 0 0.34rem;
  margin-top: 0.2rem;
}
/deep/.my-swipe.van-swipe{
  height: 2.45rem;
}
/deep/.van-swipe-item{
  width: 100%;
  img{
    height: 2.45rem;
    width: 100%;
    border-radius: 9px;
  }
}
// 通告栏
.tips{
  padding: 0 0.34rem;
  margin-top: 0.15rem;
}
.notice-swipe {
    height: 0.4rem;
    line-height: 0.4rem;
}
// 导航栏
.nav{
  padding: 0 0.34rem;
  margin-top: 0.4rem;
}
.nav-list{
  display: flex;
  border-radius: 10px;
  padding-top: 0.27rem;
  padding-bottom: 0.22rem;
  background-color: #FCFCFC;
  flex-wrap: wrap;
  .nav-item{
    width: 20%;
    font-size: 0.22rem;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
}
.nav-item{
  position: relative;
  .pic{
      width: 0.85rem;
      height: 0.85rem;
      border-radius: 50%;
      img{
        width: 100%;
        height: 100%;
      }
  }
  .text{
    margin-top: 0.1rem
  }
  a{
    display: block;
    width: 100%;
    height: 100%!important;
    position: absolute;
    left: 0;
    height: 0;
  }
}
// 主要内容
.content{
  padding: 0 0.34rem;
}
.floor-title{
  font-size: 0.3rem;
  font-weight: 600;
  margin-top: 0.4rem;
}
.title-child{
  display: flex;
  margin: 0.15rem 0;
  justify-content: space-between;
  .child-left{
    font-size: 0.24rem;
    color: #999999;
  }
  .child-right{
    font-size: 0.24rem;
    color: #F09816;
    font-weight: 600;
  }
}
// 项目列表
.project-list{
  display: flex;
  justify-content: space-around;
  margin-top: 0.3rem;
}
.project-item{
  margin-bottom: 0.35rem;
  .pic{
    width: 3.2rem;
    height: 1.98rem;
    position: relative;
    img{
      width: 100%;
      height: 100%;
    }
    .sale-img{
      position: absolute;
      width: 0.9rem;
      height: 0.3rem;
      display: flex;
      justify-content: center;
      align-items: center;
      left: 0;
      bottom: 0;
      font-size: 0.18rem;
      color: #fff;
      background-color: #EA4800;
      opacity: 0.9;
    }
    .sale-text{
      position: absolute;
      width: 0.9rem;
      height: 0.3rem;
      display: flex;
      justify-content: center;
      align-items: center;
      right: 0;
      bottom: 0;
      font-size: 0.18rem;
      color: #fff;
      background-color: #ea0000;
      opacity: 0.9;
    }
  }
  .project-text{
    display: flex;
    align-items: center;
    margin-top: 0.15rem;
    justify-content: space-between;
  }
  .projectList-name{
    font-size: 0.24rem;
    color: #333333;
    font-weight: 600;
  }
  .projectList-address{
    font-size: 0.18rem;
    color: #545454;
    margin-top: 0.15rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .project-message{
    color: #545454;
    font-size: 0.18rem;
    margin-top: 0.1rem;
  }
}
// 店铺列表
.room-list{
  display: flex;
  justify-content: space-around;
  margin-top: 0.3rem;
}
.room-item{
  margin-bottom: 0.35rem;
  .pic{
    width: 3.2rem;
    height: 1.98rem;
    position: relative;
    img{
      width: 100%;
      height: 100%;
    }
    .sale-img{
      position: absolute;
      width: 0.9rem;
      height: 0.3rem;
      display: flex;
      justify-content: center;
      align-items: center;
      left: 0;
      bottom: 0;
      font-size: 0.18rem;
      color: #fff;
      background-color: #EA4800;
      opacity: 0.9;
    }
    .sale-text{
      position: absolute;
      width: 0.9rem;
      height: 0.3rem;
      display: flex;
      justify-content: center;
      align-items: center;
      right: 0;
      bottom: 0;
      font-size: 0.18rem;
      color: #fff;
      background-color: #ea0000;
      opacity: 0.9;
    }
  }
  .room-name{
    font-size: 0.24rem;
    color: #333333;
    font-weight: 600;
    margin-top: 0.1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .room-address{
    font-size: 0.18rem;
    color: #333333;
    margin-top: 0.1rem;
  }
  .room-text{
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.1rem;
  }
  .room-area{
    font-size: 0.16rem;
    color: #545454;
  }
  .room-prices{
    font-size: 0.20rem;
    font-weight: 600;
    color: #EA4800;
  }
}
// 合作伙伴
.friend-content{
  display: flex;
  justify-content: space-around;
  align-items: center;
  margin-bottom: 0.38rem;
  .friend-title{
    display: flex;
    width: 1.3rem;
    height: 0.5rem;
    border: 1px solid #C8C8C8;
    justify-content: center;
    align-items: center;
    font-size: 0.16rem;
    border-radius: 3px;
    color: #8C8C8C;
    margin-right: 0.25rem;
  }
  .more{
    font-size: 0.14rem;
    width: 0.8rem;
  }
}
.friend-list{
    display: flex;
    flex-wrap: wrap;
    flex: 1;
    .friend-item{
      display: flex;
      align-items: center;
      margin-right: 0.1rem;
      img{
        width: 1.27rem;
        height: 0.6rem;
      }
    }
}
</style>